class CreateOrders < ActiveRecord::Migration
  def self.up
    create_table :orders do |t|
      t.string :order_no                ,:default =>'',:limit => 30 #订单号
      t.string :pnr                     ,:default =>'',:limit => 10
      t.integer :customer_id            ,:default => 1,:limit => 2  #客户编号
      t.integer :owner_id               ,:default => 1,:limit => 2  #订单所有人编号
      t.integer :creator_id             ,:default => 1,:limit => 2  #操作员编号
      t.string :status                  ,:default =>'',:limit => 10 #状态 
      t.string :order_request           ,:default =>'',:limit => 60 #客户要求
      t.integer :seat                   ,:default => 1,:limit => 1  #乘客数
      
      t.string :international           ,:default =>'',:limit => 10  #国际票
      t.string :group                   ,:default =>'',:limit => 10  #团体票
      
      t.string :web                     ,:default =>'',:limit => 10  #网络订单
      t.string :trx_id                  ,:default =>'',:limit => 60 #交易号，当定单已经支付给YeePay时，将返回交易号
      t.string :trx_status              ,:default =>'',:limit => 16 #交易状态，比如，付款成功
      t.string :payment_platform_name   ,:default =>'',:limit => 26 #支付平台的名字
      t.integer :refund_amount          ,:default => 0,:limit => 3  #退款时退回的总金额
      t.string :refund_remark           ,:default =>'',:limit => 60 #退款时的一些备注
      
      t.string :airways_code            ,:default =>'',:limit => 10 #航空公司代码 承运人
      t.date :fly_date                  #最早起飞日期
      t.string :fly_time                ,:default =>'',:limit => 10 #最早起飞时间
      
      t.string :link_man                ,:default =>'',:limit => 20 #联系人姓名
      t.string :link_tel                ,:default =>'',:limit => 25 #联系电话
      
      t.integer :sender_id              ,:default => 1,:limit => 2  #送票人
      t.string :send_address            ,:default =>'',:limit => 60 #送票地址
      t.date :send_date                 #要求送票日期
      t.string :send_time               ,:default =>'',:limit => 10  #送票时间
      t.string :send_request            ,:default =>'',:limit => 60  #送票要求
      t.string :send_printed            ,:default =>'',:limit => 10  #是否打印送票单/ 已打印/未打印
      t.integer :printer_id             ,:default => 1,:limit => 2  #派单人编号 就是打印送票单的人
      t.datetime :printer_date          #派单时间
      
      t.string :jj_address              ,:default =>'',:limit => 60  #接机地址 
      t.string :jj_time                 ,:default =>'',:limit => 10  #接机时间
      t.string :jj_request              ,:default =>'',:limit => 60  #接机要求
      t.integer :jj_man_id              ,:default => 1,:limit => 2  #接机人
      t.integer :jj_affirm_id           ,:default => 1,:limit => 2  #接机确认人
      t.datetime :jj_affirm_date        #接机确认时间
      
      t.integer :price_sum              ,:default => 0,:limit => 3  #订单总价、应收金额
      t.integer :receive_cash           ,:default => 0,:limit => 3  #收回金额
      t.string :pay_type                ,:default =>'',:limit => 10  #付款方式
      t.integer :cash_checker_id        ,:default => 1,:limit => 2  #收款人编号
      t.datetime :cash_get_date         #收款时间
      t.string :remark                  ,:default =>'',:limit => 200  #备注
      
      t.date :affirm_date               #确认日期 COF
      
      t.integer :canceler_id            ,:default => 1 ,:limit => 2#取消员
      t.datetime :cancel_date           #取消时间
      t.string :cancel_reason           ,:limit => 60  #取消原因
      
      t.integer :ticket_outer_id        ,:default => 1 ,:limit => 2#出票人编号
      t.datetime :ticket_out_date       #出票时间
      t.date :tktl_date                 #最晚出票日期
      t.string :tktl_time               ,:limit => 10 #最晚出票时间
      
      t.integer :insurance_number       ,:default => 0 ,:limit => 1 #保险份数
      t.string :insurance_outed         ,:default => '',:limit => 10 #未出/已出
      t.string :activity                ,:default =>'',:limit => 100  #活动类型
      t.string :memo                    ,:default =>'',:limit => 16   #备用
      
      t.string :payment_type            ,:limit => 16  #结算类型
      t.integer :last_editer_id         ,:default => 1 ,:limit => 2#最后编辑人
      t.integer :is_locked              ,:limit => 1 ,:default => 0 #是否管理会要锁定 1为True 0为False
      t.integer :lock_version           ,:default => 0 #乐观锁
      t.timestamps
    end
    
    add_index :orders, :order_no ,:unique=>true
    
    Order.create(:order_no=>'FJ0803150000000',:pnr=>'AAAAA',:customer_id=>2,:price_sum=>'760',:status=>'预订单',:fly_date=>'2008-09-09',:fly_time=>'13:00',:creator_id=>'2',:owner_id=>'2',:link_man=>'联系人',:link_tel=>'13500000000',:insurance_number=>2,:jj_address=>'接机地址',:jj_time=>'12:00')
    Order.create(:order_no=>'FJ0803150000001',:pnr=>'BBBBB',:customer_id=>2,:price_sum=>'930',:status=>'已取消',:fly_date=>'2008-09-09',:fly_time=>'12:00',:creator_id=>'2',:owner_id=>'2',:link_man=>'联系人',:link_tel=>'13500000044',:insurance_number=>1,:jj_address=>'接机地址',:jj_time=>'12:00',:canceler_id=>2,:cancel_date=>'2008-09-06',:cancel_reason=>'不要了')
    Order.create(:order_no=>'FJ0803150000002',:pnr=>'CCCCC',:customer_id=>2,:price_sum=>'1130',:status=>'预订单',:fly_date=>'2008-09-09',:fly_time=>'09:00',:creator_id=>'2',:owner_id=>'2',:link_man=>'联系人',:link_tel=>'13500000033',:insurance_number=>1,:jj_address=>'接机地址',:jj_time=>'05:00')
    Order.create(:order_no=>'FJ0803150000003',:pnr=>'DDDDD',:customer_id=>1,:price_sum=>'430',:status=>'预订单',:fly_date=>'2008-09-09',:fly_time=>'11:00',:creator_id=>'3',:owner_id=>'3',:link_man=>'联系人',:link_tel=>'13500000022',:insurance_number=>1,:jj_address=>'接机地址',:jj_time=>'09:00',:jj_affirm_id=>2,:jj_affirm_date=>'2008-09-06')
    Order.create(:order_no=>'FJ0803150000004',:pnr=>'FFFFF',:customer_id=>2,:price_sum=>'2060',:status=>'已出票',:fly_date=>'2008-09-09',:fly_time=>'15:00',:creator_id=>'2',:owner_id=>'2',:link_man=>'联系人',:link_tel=>'13500000011',:insurance_number=>2,:jj_address=>'接机地址',:jj_time=>'13:00',:ticket_outer_id=>2,:ticket_out_date=>'2008-09-05',:send_date=>'2008-09-05',:send_time=>'14:00',:send_address=>'青岛市市北区威海路22号202',:send_request=>'带pos机')
    
  end

  def self.down
    drop_table :orders
  end
end
